import { ListStore } from '../listStore';
import * as mobx from "mobx";
const { observable, action } = mobx;
import * as API from '../../apis/customQuery';
import * as API_REPORTFORM from '../../apis/customReportForm';

export class WFRequestListStore extends ListStore{

    title = '流程清单';
    otherSearchParams = {};
    @observable btnObj = {};
    otherInfo = {};

    @observable showModalObj = {};

    constructor() {
        super();
        this.updateOtherSearchParams = this.updateOtherSearchParams.bind(this);
        this.loadCondition = this.loadCondition.bind(this);
        this.doSearch  = this.doSearch.bind(this);
        this.clickButttonDrop  = this.clickButttonDrop.bind(this);
        this.reLoad = this.reLoad.bind(this);
        this.controlShowModal = this.controlShowModal.bind(this);
    }

    @action
    updateOtherSearchParams(params = {}) {
        this.otherSearchParams = {...this.otherSearchParams,...params};
    }

    loadCondition(){
        API.getFixedCondition().then(datas =>{
            this.condition = datas.condition;
            this.form.initFormFields(datas.condition);
        });
    }

    doSearch(params = {}) {
        //常用查询条件值
        const searchParamsCommon = this.form.getFormParams();
        //拼接查询请求参数
        let queryParams = { ...searchParamsCommon,...this.otherSearchParams};
        this.loading = true;
        API_REPORTFORM.getRequestList(queryParams).then((data) => {
            this.otherInfo = data.otherInfo;
            this.loading = false;
            this.tableStore.getDatas(data.sessionkey, params.current || 1, "", params.sortParams || []);
        });
    }

    clickButttonDrop(key){
        this.btnObj = {key:key, disabled:true};
        this.tableStore.tableUpdate({checkId:key});
        this.tableStore.reloadCurrent();
    }

    controlShowModal(key, bool=false){
        this.showModalObj = {...this.showModalObj, ...{[key]: bool}};
    }

    reLoad(){
        const current =  this.tableStore.current;
        const sortParams = this.tableStore.sortParams.toJS();
        this.doSearch({current, sortParams});
    }
}